package utils.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.myapplication.R;
import com.lanou.horo.myapplication.dbdao.FristDbEntity;

import java.util.List;

import entity.RecommendedPageEntity;
import tools.ItemOnClickListenerOther;
import volley.VolleySingleton;

/**
 * Created by dllo on 15/11/30.
 */

public class RecomenddbAdpter extends
        RecyclerView.Adapter<RecomenddbAdpter.RecommendedPageViewHolder> {

  private List<FristDbEntity> entities;
    //    private List<RecommendedPageEntity.EditorRecommendAlbumsEntity.ListEntity> eden;
    private Context context;

public void addDB(List<FristDbEntity> entities){
    this.entities = entities;
    notifyDataSetChanged();
}




    public RecomenddbAdpter(Context context) {
        this.context = context;
    }




    private boolean isListNull() {
        return entities != null && entities.size() > 0 ;
//                && eden != null && eden.size() > 0;
    }

    @Override
    public RecommendedPageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.fragment_page_recommended_item, parent, false);
        return new RecommendedPageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecommendedPageViewHolder holder, int position) {
        if (isListNull()) {
           FristDbEntity en = entities.get(position);
            if (en != null) {
               
                holder.recommendedItemContentF.setText(en.getRecommendedItemContentF());
                holder.recommendedItemContentS.setText(en.getRecommendedItemContentS());
                holder.recommendedItemContentT.setText(en.getRecommendedItemContentT());

                VolleySingleton.getInstance().getBitmap(en.getRdItemContentImgF(), holder.rdItemContentImgF);
                VolleySingleton.getInstance().getBitmap(en.getRdItemContentImgS(), holder.rdItemContentImgS);
                VolleySingleton.getInstance().getBitmap(en.getRdItemContentImgT(), holder.rdItemContentImgT);

            }
            holder.pos = position;
        }
    }

    @Override
    public int getItemCount() {
        return isListNull() ? entities.size(): 0;
    }

    public class RecommendedPageViewHolder extends RecyclerView.ViewHolder  {
        private TextView recommendedItemTitle, recommendedItemContentF, recommendedItemContentS,
                recommendedItemContentT;
        private NetworkImageView rdItemContentImgF, rdItemContentImgS, rdItemContentImgT;
        private int pos;

        public RecommendedPageViewHolder(View itemView) {
            super(itemView);
            recommendedItemTitle = (TextView) itemView.findViewById(R.id.recommendedItemTitle);
            recommendedItemContentF = (TextView) itemView.findViewById(R.id.recommendedItemContentF);
            recommendedItemContentS = (TextView) itemView.findViewById(R.id.recommendedItemContentS);
            recommendedItemContentT = (TextView) itemView.findViewById(R.id.recommendedItemContentT);

            rdItemContentImgF = (NetworkImageView) itemView.findViewById(R.id.rdItemContentImgF);
            rdItemContentImgS = (NetworkImageView) itemView.findViewById(R.id.rdItemContentImgS);
            rdItemContentImgT = (NetworkImageView) itemView.findViewById(R.id.rdItemContentImgT);

        }


    }

}